package com.qnw.CardGroupManagement.adapter;
import android.app.*;
import android.content.*;
import android.graphics.*;
import android.view.*;
import android.view.ViewGroup.*;
import android.widget.*;
import com.qnw.CardGroupManagement.*;
import com.ygo.feihua.*;
import java.io.*;
import java.util.*;

import android.graphics.drawable.*;
import android.os.*;
import java.util.zip.*;
import android.support.v4.util.*;

public class AdapterKz extends BaseAdapter
{

	private List<Card> data;
	private Context context;
	Zujian zujian;
	Gongju gj;
	int pmk;
	GridView gr;
	
	public AdapterKz(Context context,List<Card> data,GridView gr){
		this.context=context;
		this.data=data;
		this.gr=gr;
	//	setkt();
		
		gj=Gongju.getdx(context);
		
		Activity a=(Activity)context;
		Display display = a.getWindowManager().getDefaultDisplay();
		 pmk = display.getWidth();
	}
	
	class Zujian{
		ImageView kz_kt;
	}
	
	
	@Override
	public int getCount()
	{
		// TODO: Implement this method
		return data.size();
	}

	@Override
	public Object getItem(int p1)
	{
		// TODO: Implement this method
		return data.get(p1);
	}

	@Override
	public long getItemId(int p1)
	{
		// TODO: Implement this method
		return p1;
	}

	@Override
	public View getView(final int position, View p2, ViewGroup p3)
	{
		if(p2==null){
			zujian=new Zujian();
			p2=LayoutInflater.from(context).inflate(R.layout.item_kz,null);
			zujian.kz_kt=(ImageView) p2.findViewById(R.id.kz_kt);
			LayoutParams para;  
			para = zujian.kz_kt.getLayoutParams();  
			int wi=pmk/10;

			para.width=wi;
			para.height=wi*7/5;
			zujian.kz_kt.setLayoutParams(para);
			p2.setTag(zujian);
		}else{
			
			zujian=(Zujian)p2.getTag();
		}
		String id=data.get(position).getId();
		/*	if(bii.containsKey(id)){
			zujian.kz_kt.setImageBitmap(bii.get(id));
		}*/
		
		Gongju.setKt(context,zujian.kz_kt,id);

		// TODO: Implement this method
		return p2;
	}
	
	
	Map<String,Bitmap> bii=new ArrayMap<String,Bitmap>();
	
	public  void setkt(){
		
		
		
	/*	new Thread(new Runnable(){

				@Override
				public void run()
				{
					for(Card cc:data){
						String id=cc.getId();
						bii.put(id,gj.getkt(id));
						Message me=new Message();
						me.what=0;
						han.sendMessage(me);
					}
					
					// TODO: Implement this method
				}
			}).start();*/
		
	}
	
	Handler han=new Handler(){

		@Override
		public void handleMessage(Message msg)
		{
			// TODO: Implement this method
			super.handleMessage(msg);
			
			switch(msg.what){
				case 0:
					notifyDataSetInvalidated();
					break;
				
			}
		}
		
		
		
	};
	
}
